﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using XamlingCore.SL.Controls.Content;

namespace XamlingCore.SL.Controls.Dialog
{
    [TemplatePart(Name="headerContentPresenter", Type=typeof(ContentPresenter))]
    [TemplatePart(Name = "footerContentPresenter", Type = typeof(ContentPresenter))]
    public class XHeaderedContentControl : XTransitionContentControl
    {
        public XHeaderedContentControl()
        {
            
        }


        protected virtual void OnHeaderContentChanged(object oldContent, object newContent)
        {
            
        }

        protected virtual void OnFooterContentChanged(object oldValue, object newValue)
        {
            
        }

        protected override void OnContentChanged(object oldContent, object newContent)
        {
            base.OnContentChanged(oldContent, newContent);
        }

        public DataTemplate FooterContentTemplate
        {
            get { return (DataTemplate)GetValue(FooterContentTemplateProperty); }
            set { SetValue(FooterContentTemplateProperty, value); }
        }

        // Using a DependencyProperty as the backing store for FooterContentTemplate.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FooterContentTemplateProperty =
            DependencyProperty.Register("FooterContentTemplate", typeof(DataTemplate), typeof(XHeaderedContentControl), null);

        

        public DataTemplate HeaderContentTemplate
        {
            get { return (DataTemplate)GetValue(HeaderContentTemplateProperty); }
            set { SetValue(HeaderContentTemplateProperty, value); }
        }

        // Using a DependencyProperty as the backing store for HeaderContentTemplate.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderContentTemplateProperty =
            DependencyProperty.Register("HeaderContentTemplate", typeof(DataTemplate), typeof(XHeaderedContentControl), null);

        // Using a DependencyProperty as the backing store for HeaderContent.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderContentProperty =
            DependencyProperty.Register("HeaderContent", typeof(object), typeof(XHeaderedContentControl), new PropertyMetadata(null, HeaderContentChanged));


        public object HeaderContent
        {
            get { return (object)GetValue(HeaderContentProperty); }
            set { SetValue(HeaderContentProperty, value); }
        }



        public object FooterContent
        {
            get { return (object)GetValue(FooterContentProperty); }
            set { SetValue(FooterContentProperty, value); }
        }

        // Using a DependencyProperty as the backing store for FooterContent.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FooterContentProperty =
            DependencyProperty.Register("FooterContent", typeof(object), typeof(XHeaderedContentControl), new PropertyMetadata(null, FooterContentChanged));

        private static void FooterContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var obj = d as XHeaderedContentControl;

            if (obj != null)
            {
                obj.OnFooterContentChanged(e.OldValue, e.NewValue);
            }
        }

        private static void HeaderContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var obj = d as XHeaderedContentControl;

            if(obj!=null)
            {
                obj.OnHeaderContentChanged(e.OldValue, e.NewValue);
            }
        }
    }
}
